#include <Arduino.h>
#include "button.h"

#define KEYA 8
#define KEYB 7

void Button_Init(void)
{
    pinMode(KEYA, INPUT_PULLUP);
    pinMode(KEYB, INPUT_PULLUP);
} 


uint8_t Button_Check(void)
{
    bool buttonState;
    buttonState = digitalRead(KEYA);//读取当前按键状态
    if(buttonState == LOW){
        //按键按下
        delay(40);//做一个防抖动延时(确保真是按下了按键而不是错误)
        buttonState = digitalRead(KEYA);//再一次读取按键状态
        if(buttonState == LOW){
            while (digitalRead(KEYA) == LOW);
            
        //再次确认是否真的按下了按键,是的话就置反当前灯的状态
            return 1;
        }
    }

     buttonState = digitalRead(KEYB);//读取当前按键状态
    if(buttonState == LOW){
        //按键按下
        delay(40);//做一个防抖动延时(确保真是按下了按键而不是错误)
        buttonState = digitalRead(KEYB);//再一次读取按键状态
        if(buttonState == LOW){
        //再次确认是否真的按下了按键,是的话就置反当前灯的状态
            while (digitalRead(KEYB) == LOW);
            return 2;
        }
    }

    return 0;
}